<template>
  <view class="license-plate-container">
    <view class="header-container">
      <view class="left" @tap="toBack"><text class="iconfont icon-back"></text></view>
      <view class="center">车牌输入</view>
      <view class="right">
      </view>
    </view>
    <view class="main-container">
      <view class="help-message">请输入真实有效车牌</view>
      <view class="plate-input-container">
        <view class="plate-input-wrapper">
          <input
            class="plate-input"
            placeholder="请点此输入"
            v-model.trim="plateNo"
            disabled="true"
          />
          <view style="position: absolute; top: 0px; bottom: 0px; left: 0px; right: 0px;" @tap="plateShow = true"></view>
        </view>
      </view>
      <view class="plate-action-container">
        <button class="bind-btn" @click="submit">确认输入</button>
      </view>
      <plateInput
        v-if="plateShow"
        :plate="plateNo"
        @export="setPlate"
        @close="plateShow = false"
      />
    </view>
  </view>
</template>
<script lang="ts">
import Vue from "vue";
import plateInput from "@/components/uni-plate-input/uni-plate-input.vue";

export default Vue.extend({
  components: { plateInput },
  onLoad(option: any) {
    if (option.next_path) {
      this.nextPath = option.next_path;
    }
  },
  data() {
    return {
      plateNo: "",
      plateShow: false,
      nextPath: ""
    };
  },
  methods: {
    toBack() {
      uni.navigateBack({ delta: 1 })
    },
    setPlate(plate: string) {
      if (plate.length >= 7) this.plateNo = plate;
      this.plateShow = false;
    },
    submit() {
      if (this.nextPath) {
        uni.redirectTo({
          url: decodeURI(this.nextPath) + "?plate_no=" + this.plateNo
        });
      }
    }
  },
});
</script>
<style>
.license-plate-container {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.header-container {
  color: #fff;
  height: 24px;
  padding: 15px;
  flex-shrink: 0;
  display: flex;
  background: #006b65;
}

.header-container .left,
.header-container .right {
  font-size: 16px;
  width: 100px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.header-container .center {
  flex-grow: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

.main-container {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.help-message {
  color: #808080;
  font-size: 12px;
  margin-bottom: 15px;
  text-align: center;
}

.plate-input-container {
  padding-left: 15px;
  padding-right: 15px;
  margin-bottom: 15px;
}

.plate-input-container .plate-input-wrapper {
  border: 1px solid #808080;
  padding: 5px 15px;
  border-radius: 5px;
  position: relative;
}

.plate-action-container {
  padding: 0px 15px;
  margin-bottom: 20vh;
}

.plate-action-container .bind-btn {
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
  background: #006b65;
}
</style>